<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>快递物流系统</title>
<link rel="stylesheet" href="lib/layui/css/layui.css" media="all" />

<script type="text/javascript" src="lib/layui/layui.js"></script>
<style>
.layui-input {
	width: 300px;
	display: inline;
	position: relative;
	top: 1px;
}
</style>
</head>

<body
	style="background-color: white; padding: 40px 20px 20px 20px; overflow-y: scroll;">
	<div class="layui-inline">
		<div class="layui-inline">
		<input type="hidden" id="idx">
			<input  type="text" name="name" required=""
				lay-verify="required" placeholder="目的地名称" autocomplete="off"
				class="layui-input"> 
				<input type="text" name="detailed_address_id" required="" lay-verify="required" placeholder="目的地编号"
				autocomplete="off" class="layui-input">
			<button class="layui-btn" onclick="searchss();">
				<i class="layui-icon"></i> 搜索
			</button>
		</div>
	</div>
	<table id="demo" lay-filter="test"></table>
	
	<script type="text/html" id="barDemo"> 
		<a onclick="use();" class="layui-btn layui-btn-xs" lay-event="edit">选择</a>
	</script>
	<script type="text/javascript">  
  
    layui.use(['table','layer', 'jquery'], function(){
	  table = layui.table;
	  $ = layui.$;
	  table.render({
	    elem: '#demo'
	    ,url: 'api/dest?op=list'
	    ,page: true //开启分页
	    ,id: 'destTable'
	    ,cols:[[ 
	    	{
				title: "全选",
				width: 50,
				type: "checkbox",
				fixed: 'left'}
     	  	  ,{title: '序号',type:'numbers'}
     	      ,{field: 'id', title: '编号',width:130}
     	      ,{field: 'name', title: '目的地网点名',width:120}
     	      ,{field: 'detailed_address_id', title: '目的地编号',width:180}
     	      ,{field: 'id', title: '操作',width:120,toolbar: '#barDemo',align:'center', fixed: 'right'}	
     	    ]]
	  });	  	  
	});

	function searchss(){	

		  table.reload('table', {
			 
			  where: {
				  name : $("[name='name']").val(),
				  detailed_address_id: $("[name='detailed_address_id']").val()
			  }
			  ,page: {
    		    curr: 1 //重新从第 1 页开始
  		  }
		  });
	 }
	 
	 function use(){
		  var checkStatus = table.checkStatus('destTable');
           data = checkStatus.data;
          var name = null;
          var id = null;
          for ( var idx in data) {
        	  name =data[0].name;
        	  id =data[0].detailed_address_id;
          }
		console.log("父的index"+$("#idx").val())
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         var body = parent.layer.getChildFrame('body', $("#idx").val()-1);
         
         body.find("#destination_network_name").val(name);
         body.find("[name='destination_network_id']").val(id);
	       // TEST.chooseCallBack("123");
	       //当你在iframe页面关闭自身时
		parent.layer.close(index);
	 }
  
  
  </script>
</body>
</html>